package com.cgsd.heyu.presenter.home;


import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;

import com.android.library.utils.AesUtil;
import com.android.library.utils.BeanUtils;
import com.android.library.utils.SharedPreferencesHelper;
import com.apkfuns.logutils.LogUtils;
import com.cgsd.heyu.common.Helper;
import com.cgsd.heyu.entity.VideoRewordResult;
import com.cgsd.heyu.http.RetrofitServiceManagerPhp;
import com.google.gson.Gson;
import com.cgsd.heyu.api.ApiService;
import com.cgsd.heyu.common.CommonConfig;
import com.cgsd.heyu.common.Constants;
import com.cgsd.heyu.common.UserModeConfig;
import com.cgsd.heyu.entity.AdContentEntity;
import com.cgsd.heyu.entity.AppUpdateEntity;
import com.cgsd.heyu.entity.BannerEntity;
import com.cgsd.heyu.entity.CashOutAccountEntity;
import com.cgsd.heyu.entity.CashOutEntity;
import com.cgsd.heyu.entity.CashOutProductEntity;
import com.cgsd.heyu.entity.ConfigEntity;
import com.cgsd.heyu.entity.FlowerInfoEntity;
import com.cgsd.heyu.entity.IntegralEntity;
import com.cgsd.heyu.entity.PayEntity;
import com.cgsd.heyu.entity.ReportEntity;
import com.cgsd.heyu.entity.RewardEntity;
import com.cgsd.heyu.entity.TaskEntity;
import com.cgsd.heyu.entity.TeamEntity;
import com.cgsd.heyu.entity.UploadTokenEntity;
import com.cgsd.heyu.entity.VideoEntity;
import com.cgsd.heyu.entity.VipEntity;
import com.cgsd.heyu.entity.VipProductEntity;
import com.cgsd.heyu.http.BaseResponse;
import com.cgsd.heyu.http.BaseRxSubscribe;
import com.cgsd.heyu.http.ErrorMessage;
import com.cgsd.heyu.http.RetrofitServiceManager;
import com.cgsd.heyu.http.RxjavaHelper;
import com.cgsd.heyu.ui.Integral.fragment.IntegralDetailFragment;
import com.cgsd.heyu.ui.info.CashOutActivity;

import java.util.HashMap;
import java.util.List;

import okhttp3.RequestBody;

/**
 * @author xiaoxing
 * 用户相关
 */
public class HomePresenter implements HomeContract.Presenter {
    private HomeContract.MainView mMainView;
    private HomeContract.ClassifyView mClassifyView;
    private HomeContract.CenterView mCenterView;
    private HomeContract.RewordDialogView mRewordDialogView;
    private HomeContract.MyTeamView mMyTeamView;
    private HomeContract.VideoView mVideoView;
    private HomeContract.VideoPayView mVideoPayView;
    private HomeContract.CashOutView mCashOutView;
    private HomeContract.CashOutRecordView mCashOutRecordView;
    private HomeContract.VipView mVipView;
    private HomeContract.IntegralRecordView mIntegralRecordView;

    public HomePresenter(HomeContract.MainView view) {
        mMainView = BeanUtils.checkNotNull(view);
        mMainView.setPresenter(this);
    }

    public HomePresenter(HomeContract.ClassifyView view) {
        mClassifyView = BeanUtils.checkNotNull(view);
        mClassifyView.setPresenter(this);
    }

    public HomePresenter(HomeContract.CenterView view) {
        mCenterView = BeanUtils.checkNotNull(view);
        mCenterView.setPresenter(this);
    }

    public HomePresenter(HomeContract.RewordDialogView view) {
        mRewordDialogView = BeanUtils.checkNotNull(view);
        mRewordDialogView.setPresenter(this);
    }

    public HomePresenter(HomeContract.MyTeamView view) {
        mMyTeamView = BeanUtils.checkNotNull(view);
        mMyTeamView.setPresenter(this);
    }

    public HomePresenter(HomeContract.VideoView view) {
        mVideoView = BeanUtils.checkNotNull(view);
        mVideoView.setPresenter(this);
    }

    public HomePresenter(HomeContract.VideoPayView view) {
        mVideoPayView = BeanUtils.checkNotNull(view);
        mVideoPayView.setPresenter(this);
    }

    public HomePresenter(HomeContract.CashOutView view) {
        mCashOutView = BeanUtils.checkNotNull(view);
        mCashOutView.setPresenter(this);
    }

    public HomePresenter(HomeContract.CashOutRecordView view) {
        mCashOutRecordView = BeanUtils.checkNotNull(view);
        mCashOutRecordView.setPresenter(this);
    }

    public HomePresenter(HomeContract.VipView view) {
        mVipView = BeanUtils.checkNotNull(view);
        mVipView.setPresenter(this);
    }

    public HomePresenter(HomeContract.IntegralRecordView view) {
        mIntegralRecordView = BeanUtils.checkNotNull(view);
        mIntegralRecordView.setPresenter(this);
    }

    @Override
    public void start() {

    }


    @Override
    public void getQiniuyunImageToken() {
        HashMap<String, Object> data = new HashMap<>(1);
        data.put("fileType", "1");
        String json = new Gson().toJson(data);
        RequestBody requestBody = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), json);
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .getQiniuyunToken(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<UploadTokenEntity>>() {
                    @Override
                    public void onSuccess(BaseResponse<UploadTokenEntity> baseResponse) {
                        SharedPreferencesHelper.saveBeanByFastJson(Constants.ShareKeyValue.IMAGE_TOKEN_DATA, baseResponse.getBizBody());
                    }

                    @Override
                    public void onError(ErrorMessage error) {

                    }
                });
    }


    @Override
    public void getTodayTask() {
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .getTaskList()
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<List<TaskEntity>>>() {
                    @Override
                    public void onSuccess(BaseResponse<List<TaskEntity>> baseResponse) {
                        LogUtils.e("getTodayTask"+"\n"+baseResponse.toString());
                        if (mClassifyView != null) {
                            mClassifyView.setTaskList(baseResponse.getBizBody());
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                       // LogUtils.e("getTodayTask"+error.getBody().toString());
                        if (mClassifyView != null) {
                            mClassifyView.setErrorMessage(error);
                        }
                    }
                });
    }


    @Override
    public void getConfigInfo(String sysType) {
        HashMap<String, Object> data = new HashMap<>();
        if (sysType != null) {
            data.put("sysType", sysType);
        }
        data.put("currentPage", 1);
        data.put("pageSize", 100);
        RequestBody requestBody = RetrofitServiceManager.getBody(data);
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .getConfigInfo(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<List<ConfigEntity>>>() {
                    @Override
                    public void onSuccess(BaseResponse<List<ConfigEntity>> baseResponse) {
                        setCommonConfig(baseResponse.getBizBody(), sysType);
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mMainView != null) {
                            mMainView.setErrorMessage(error);
                        }
                    }
                });


    }

    @Override
    public void getFlowerInfo(String userId) {
        HashMap<String, Object> data = new HashMap<>();
        data.put("userId", userId);
        RequestBody requestBody = RetrofitServiceManager.getBody(data);
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .getFlowerInfo(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<FlowerInfoEntity>>() {
                    @Override
                    public void onSuccess(BaseResponse<FlowerInfoEntity> baseResponse) {
                        if (mCenterView != null) {
                            mCenterView.setFlowerInfo(baseResponse.getBizBody());
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mCenterView != null) {
                            mCenterView.setErrorMessage(error);
                        }
                    }
                });
    }


    @Override
    public void getBannerType(String bannerType) {
        HashMap<String, Object> data = new HashMap<>();
        data.put("bannerType", bannerType);
        RequestBody requestBody = RetrofitServiceManager.getBody(data);
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .getBannerType(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<List<BannerEntity>>>() {
                    @Override
                    public void onSuccess(BaseResponse<List<BannerEntity>> baseResponse) {
                        if (mCenterView != null) {
                            mCenterView.setBanner(baseResponse.getBizBody());
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mCenterView != null) {
                            mCenterView.setErrorMessage(error);
                        }
                    }
                });
    }


    @Override
    public void getAdContent(String type) {
        HashMap<String, Object> data = new HashMap<>();
        data.put("locationId", type);
        RequestBody requestBody = RetrofitServiceManager.getBody(data);
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .getAdContent(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<AdContentEntity>>() {
                    @Override
                    public void onSuccess(BaseResponse<AdContentEntity> baseResponse) {
                        if (mRewordDialogView != null) {
                            mRewordDialogView.setAdContent(baseResponse.getBizBody(), type);
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mRewordDialogView != null) {
                            mRewordDialogView.setErrorMessage(error);
                        }
                    }
                });
    }

    @Override
    public void getTaskReword(String taskId) {
        String userId = UserModeConfig.getInstance().userId;
        HashMap<String, Object> data = new HashMap<>();
        data.put("taskId", taskId);
        data.put("keycode", AesUtil.aesEncrypt(taskId+userId+"wjsou2a*p$9@m^xa_ywaj"));
        Log.e("任务完成 获取奖励 ",taskId);
        RequestBody requestBody = RetrofitServiceManager.getBody(data);
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .taskReword(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<RewardEntity>>() {
                    @Override
                    public void onSuccess(BaseResponse<RewardEntity> baseResponse) {
                        LogUtils.e("getTaskReword success "+baseResponse.toString());
                        if (mClassifyView != null) {
                            mClassifyView.taskRewordSuccess(baseResponse.getBizBody());
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mClassifyView != null) {
                            mClassifyView.setErrorMessage(error);
                        }
                    }
                });
    }

    @Override
    public void getTaskReword(String codeId,int type) {

        HashMap<String, Object> data = new HashMap<>();
        data.put("codeId", codeId);
        data.put("type", String.valueOf(type));

        String token = Helper.getTokenPhpInfo();
        LogUtils.e("token "+token);
        RequestBody requestBody = RetrofitServiceManager.getBody(data);
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .adVideoReward(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<RewardEntity>>() {
                    @Override
                    public void onSuccess(BaseResponse<RewardEntity> baseResponse) {
                        LogUtils.e("getTaskReword success "+baseResponse.toString());
                        if (mVideoView != null) {
                            mVideoView.taskRewordSuccess(baseResponse.getBizBody());
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        LogUtils.e(""+error.toString());
                        if (mVideoView != null) {
                            mVideoView.setErrorMessage(error);
                        }
                    }
                });
    }
    @Override
    public void appUpdate() {
        HashMap<String, Object> data = new HashMap<>();
        data.put("appType", "1");
        RequestBody requestBody = RetrofitServiceManager.getBody(data);
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .appUpdate(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<AppUpdateEntity>>() {
                    @Override
                    public void onSuccess(BaseResponse<AppUpdateEntity> baseResponse) {
                        if (mMainView != null) {
                            mMainView.setAppUpdate(baseResponse.getBizBody());
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mMainView != null) {
                            mMainView.setErrorMessage(error);
                        }
                    }
                });
    }

    @Override
    public void getTeamData() {
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .getTeamData()
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<TeamEntity>>() {
                    @Override
                    public void onSuccess(BaseResponse<TeamEntity> baseResponse) {
                        LogUtils.e("getTeamData "+baseResponse.getBizBody());
                        if (mMyTeamView != null) {
                            mMyTeamView.setTeamData(baseResponse.getBizBody());
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mMyTeamView != null) {
                            mMyTeamView.setErrorMessage(error);
                        }
                    }
                });
    }

    @Override
    public void recommendUserList(int page, int pageSize, int recommendType) {
        HashMap<String, Object> data = new HashMap<>();
        data.put("currentPage", page);
        data.put("pageSize", pageSize);
        data.put("recommendType", recommendType);
        RequestBody requestBody = RetrofitServiceManager.getBody(data);
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .recommendUserList(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<List<VipEntity>>>() {
                    @Override
                    public void onSuccess(BaseResponse<List<VipEntity>> baseResponse) {
                        if (mMyTeamView != null) {
                            mMyTeamView.vipList(baseResponse.getBizBody());
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mMyTeamView != null) {
                            mMyTeamView.setErrorMessage(error);
                        }
                    }
                });
    }

    @Override
    public void getVideoList(int page, int pageSize) {
        HashMap<String, Object> data = new HashMap<>();
        data.put("currentPage", page);
        data.put("pageSize", pageSize);
        RequestBody requestBody = RetrofitServiceManager.getBody(data);
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .getVideoList(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<List<VideoEntity>>>() {
                    @Override
                    public void onSuccess(BaseResponse<List<VideoEntity>> baseResponse) {
                        LogUtils.e("视频列表  "+baseResponse.getBizBody());
                        if (mVideoView != null) {
                            mVideoView.setVideoData(baseResponse.getBizBody());
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mVideoView != null) {
                            mVideoView.setErrorMessage(error);
                        }
                    }
                });
    }

    @Override
    public void statisticsVideoData(String videoId) {
        String userId = UserModeConfig.getInstance().userId;
        HashMap<String, Object> data = new HashMap<>();
        data.put("videoId", videoId);
        data.put("keycode", AesUtil.aesEncrypt(videoId+userId+"wjsou2a*p$9@m^xa_ywaj"));
        RequestBody requestBody = RetrofitServiceManager.getBody(data);
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .statisticsVideoData(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<Void>>() {
                    @Override
                    public void onSuccess(BaseResponse<Void> baseResponse) {
                    }

                    @Override
                    public void onError(ErrorMessage error) {

                    }
                });
    }

    @Override
    public void report(ReportEntity entity) {
        RequestBody requestBody = RetrofitServiceManager.getBody(entity);
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .report(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<Void>>() {
                    @Override
                    public void onSuccess(BaseResponse<Void> baseResponse) {
                        if (mVideoPayView != null) {
                            mVideoPayView.reportSuccess();
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mVideoPayView != null) {
                            mVideoPayView.setErrorMessage(error);
                        }
                    }
                });
    }

    @Override
    public void cashOutProduct() {
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .cashOutProductList()
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<List<CashOutProductEntity>>>() {
                    @Override
                    public void onSuccess(BaseResponse<List<CashOutProductEntity>> baseResponse) {
                        LogUtils.e("cashoutProduct "+baseResponse.toString());
                        if (mCashOutView != null) {
                            mCashOutView.cashOutProduct(baseResponse.getBizBody());
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mCashOutView != null) {
                            mCashOutView.setErrorMessage(error);
                        }
                    }
                });
    }

    @Override
    public void cashOutAccountBind(String name, String account, String type) {
        HashMap<String, Object> data = new HashMap<>();
        if (CashOutActivity.CASH_OUT_WEIXIN.equals(type)) {
            data.put("wxWithdrawAccount", account);
            data.put("wxWithdrawName", name);
        } else {
            data.put("aliWithdrawAccount", account);
            data.put("aliWithdrawName", name);
        }
        RequestBody requestBody = RetrofitServiceManager.getBody(data);
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .cashOutBind(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<Void>>() {
                    @Override
                    public void onSuccess(BaseResponse<Void> baseResponse) {
                        if (mCashOutView != null) {
                            mCashOutView.bindSuccess();
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mCashOutView != null) {
                            mCashOutView.setErrorMessage(error);
                        }
                    }
                });
    }

    @Override
    public void cashOutAccountInfo() {
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .cashOutAccountInfo()
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<CashOutAccountEntity>>() {
                    @Override
                    public void onSuccess(BaseResponse<CashOutAccountEntity> baseResponse) {
                        LogUtils.e("cashOutAccountInfo "+baseResponse.toString());
                        if (mCashOutView != null) {
                            mCashOutView.cashOutAccountInfo(baseResponse.getBizBody());
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        //LogUtils.e("onError "+error.getMessage()+"\n"+error.getBody()+"\n"+error.getCode());
                        if (mCashOutView != null) {
                            mCashOutView.setErrorMessage(error);
                        }
                    }
                });
    }

    @Override
    public void cashOut(String productId, String payWay) {
        HashMap<String, Object> data = new HashMap<>();
        data.put("seqId", productId);
        data.put("withdrawType", payWay);
        RequestBody requestBody = RetrofitServiceManager.getBody(data);
        // TODO: 2021/4/5  RetrofitServiceManager 改为 RetrofitServiceManagerPhp
        RetrofitServiceManagerPhp.getInstance().creat(ApiService.class)
                .cashOut(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<Void>>() {
                    @Override
                    public void onSuccess(BaseResponse<Void> baseResponse) {
                        if (mCashOutView != null) {
                            mCashOutView.cashOutSuccess();
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mCashOutView != null) {
                            mCashOutView.setErrorMessage(error);
                        }
                    }
                });
    }

    @Override
    public void cashOutRecord(int page) {
        HashMap<String, Object> data = new HashMap<>();
        data.put("currentPage", page);
        data.put("pageSize", 20);
        RequestBody requestBody = RetrofitServiceManager.getBody(data);
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .cashOutRecord(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<List<CashOutEntity>>>() {
                    @Override
                    public void onSuccess(BaseResponse<List<CashOutEntity>> baseResponse) {
                        if (mCashOutRecordView != null) {
                            mCashOutRecordView.cashOutList(baseResponse.getBizBody());
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mCashOutRecordView != null) {
                            mCashOutRecordView.setErrorMessage(error);
                        }
                    }
                });
    }

    @Override
    public void vipProduct() {
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .vipProductList()
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<List<VipProductEntity>>>() {
                    @Override
                    public void onSuccess(BaseResponse<List<VipProductEntity>> baseResponse) {
                        LogUtils.e("vipProduct "+baseResponse.toString());
                        if (mVipView != null) {
                            mVipView.vipProduct(baseResponse.getBizBody());
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mVipView != null) {
                            mVipView.setErrorMessage(error);
                        }
                    }
                });
    }

    @Override
    public void alipay(String orderNo) {
        HashMap<String, Object> data = new HashMap<>();
        data.put("orderNo", orderNo);
        RequestBody requestBody = RetrofitServiceManager.getBody(data);
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .alipay(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<PayEntity>>() {
                    @Override
                    public void onSuccess(BaseResponse<PayEntity> baseResponse) {
                        if (mVipView != null) {
                            mVipView.setAlipayData(baseResponse.getBizBody());
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mVipView != null) {
                            mVipView.setErrorMessage(error);
                        }
                    }
                });
    }

    @Override
    public void thirdAlipay(String orderNo, Context mContext) {

        String topic = "alipays://platformapi/startapp?saId=10000007&qrcode=";
// 从汇付正扫接口获取的参数（以下值仅为示例）
        String qrcodeUrl = "https://qr.alipay.com/bax02911brluc2xieoph6001";
// 字符串拼接
        String jumpUrl = topic + orderNo;
// 按以上示例拼接得出结果
// jumpUrl 为 alipays://platformapi/startapp?saId=10000007&qrcode=https://qr.alipay.com/bax02911brluc2xieoph6001

        Intent intent = new Intent();
        intent.setAction("android.intent.action.VIEW");
// jumpUrl 为先前示例中拼装的 url
        Uri contentUrl = Uri.parse(jumpUrl);
        intent.setData(contentUrl);
        mContext.startActivity(intent);


    }

    @Override
    public void getUserInfo() {
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .getUserInfo()
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<UserModeConfig>>() {
                    @Override
                    public void onSuccess(BaseResponse<UserModeConfig> baseResponse) {
                        if (mVipView != null) {
                            mVipView.setUserInfo(baseResponse.getBizBody());
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mVipView != null) {
                            mVipView.setErrorMessage(error);
                        }
                    }
                });
    }

    @Override
    public void getIntegralRecord(int page, String operationType) {
        HashMap<String, Object> data = new HashMap<>();
        data.put("currentPage", page);
        data.put("pageSize", 20);
        if (!IntegralDetailFragment.TYPE_ALL.equals(operationType)) {
            data.put("operationType", operationType);
        }
        RequestBody requestBody = RetrofitServiceManager.getBody(data);
        RetrofitServiceManager.getInstance().creat(ApiService.class)
                .getIntegralRecord(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<List<IntegralEntity>>>() {
                    @Override
                    public void onSuccess(BaseResponse<List<IntegralEntity>> baseResponse) {
                        if (mIntegralRecordView != null) {
                            mIntegralRecordView.setIntegralData(baseResponse.getBizBody());
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        if (mIntegralRecordView != null) {
                            mIntegralRecordView.setErrorMessage(error);
                        }
                    }
                });
    }

    @Override
    public void videoReward(String videoId) {
        HashMap<String, Object> data = new HashMap<>();
        data.put("videoId", videoId);
        RequestBody requestBody = RetrofitServiceManager.getBody(data);
        // TODO: 2021/4/5 RetrofitServiceManager 改为 RetrofitServiceManagerPhp
        RetrofitServiceManagerPhp.getInstance().creat(ApiService.class)
                .videoReward(requestBody)
                .compose(RxjavaHelper.observeOnMainThread())
                .subscribe(new BaseRxSubscribe<BaseResponse<VideoRewordResult>>() {
                    @Override
                    public void onSuccess(BaseResponse<VideoRewordResult> baseResponse) {
                        LogUtils.e("videoReward "+baseResponse.getBizBody().toString());
                        if (mVideoPayView != null) {
                            mVideoPayView.videoReword(baseResponse.getBizBody());
                        }
                    }

                    @Override
                    public void onError(ErrorMessage error) {
                        //LogUtils.e("videoReward error"+error.getBody().toString());
                    }
                });
    }


    private void setCommonConfig(List<ConfigEntity> entities, String sysType) {
        if (BeanUtils.isEmpty(entities)) {
            return;
        }
        if (sysType == null) {
            CommonConfig.setCommonConfig(entities);
        }
        if (ConfigEntity.DONATION_NUM.equals(sysType)) {
            CommonConfig commonConfig = CommonConfig.getInstance();
            commonConfig.donationNum = entities;
            CommonConfig.setCommonConfig(commonConfig);
        }
        if (mMainView != null) {
            mMainView.setConfig(sysType);
        }
        if (mClassifyView != null) {
            mClassifyView.setConfig(sysType);
        }
    }
}
